<template>
    <div>
        <h2>欢迎亲的注册</h2>
        <p>
            用户名:<input type="text" v-model="username" />
        </p>
        <p>
            密码:<input type="password" v-model="userpass" />
        </p>
        <p>
            重复密码:<input type="password" v-model="userpass2"/>
        </p>
        <p>
            <input type="button" value="注册" @click="regSave" />
        </p>
    </div>
</template>

<script>

import axios from "axios";

export default {
    name:"Reg",
    data(){
        return {
            username:"",
            userpass:"",
            userpass2:""
        }
    },
    methods:{
        regSave(){
            // 1、前端的验证（正则，两次密码是否一致）；

            // 2、发送请求

            // let data = new URLSearchParams();
            // data.append("username",this.username);
            // data.append("userpass",this.userpass);

            axios({
                url:"http://localhost:3000/vips",
                method:"post",
                data
            })
            .then(res=>{
                console.log("res.data",res.data);
                if(res.data.username==this.username){
                    alert("注册成功！");
                }
            })
            .catch(err=>{
                console.log("出错了",err);
            })
        }
    }
}
</script>

<style scoped>

</style>

